function pushLabel(tid, label) {
	if (+tid <= 0 || isEmpty(label)) {
		return -1;
	}
	var res = -1;
	jQuery.ajax({
		url: "/shequ/new/addLabel.do",
		type: "POST",
		dataType: "json",
		data: {
			label: label,
			tid: tid
		},
		async: false,
		success: function (data) {
			res = +data;
		}
	});
	return res;
}

function rmLabel(tid, lid) {
	if (+lid <= 0 || +tid <= 0) {
		return -1;
	}
	var res = -1;
	jQuery.ajax({
		url: "/shequ/new/rmLabel.do",
		type: "POST",
		dateType: "json",
		async: false,
		data: {
			lid: lid,
			tid: tid
		},
		success: function (data) {
			res = +data;
		}
	});
	return res;
}

function bbsViewNum(tmp) {
    if (typeof(tmp) != 'undefined') {
        if (tmp == 0) {
            jQuery.post("/shequ/statistic/bbs.do", {info:"viewNum", flag:"1"});
            return;
        }
    }
    jQuery.post("/shequ/statistic/bbs.do", {info:"viewNum"});
}
function showToTop() {
    jQuery(window).scroll(function () {
        var top = jQuery(window).scrollTop();
        var height = screen.availHeight;
        var bottom = jQuery("#allFooter").offset().top;
        if (top - height > 0) {
            if(!showFlag){
                jQuery("#toTop").show();
                if(height-bottom <= 150){
                    jQuery("#toTop").css("bottom","180px");
                }else{
                    jQuery("#toTop").css("bottom","30px");
                }
                showFlag = true;
            }
        } else {
            if(showFlag){
                jQuery("#toTop").hide();
                showFlag = false;
            }
        }
    });
}
function confirmDelete(pid){
    addTip(null, shequ_sureDelete, shequ_confirm, shequ_cancel);
    showTips({
        sure:function(){removePost(pid);}
    });
}
function removePost(pid){
    jQuery.ajax({
        url:"/shequ/new/post/del.do",
        type:"POST",
        dataType:"text",
        data:{
            pid:pid
        },
        complete:function(xmlRequest){
            var data = xmlRequest.responseText;
            if(data == "success"){
                window.location.reload();
            }else if(data == "noPower") {
                addTip("你没有权限，你删个毛线！");
                showTips();
            }else if(data == "error"){
                addTip(shequ_deleteError);
                showTips();
            }else if(data == "hadDeleted"){
                addTip("都删了你还删！你是猪吗！");
                showTips();
            }else if(data == "notLogin"){
                addTip("请先登录！");
                showTips();
            }
        }
    });
}
function isEmptyContent(content, fn){
    if (!isEmpty(content)) {
        fn.con();
    } else {
        fn.can();
    }
}
function isEmpty(str){
    if(str == null){
        return true;
    }
    str = jQuery.trim(str);
    if(str == ""){
        return true;
    }
    return false;
}
function emptyInfo(){
    addTip(null, shequ_emptyReply);
    showTips();
}
function toLogin(info){
    addTip(null, info, login, shequ_cancel);
    showTips({
        sure:function(){
           location.href = '/user/login.do';
        }
    });
}
function confirm(tid, fid1, fid2){
	addTip(null, shequ_sureDeleteTheme, shequ_confirm, shequ_cancel);
	showTips({
		sure:function(){
			removeTheme(tid, fid1, fid2);
		}
	});
}
function addTip(tipTitle, tipInfo, sure, cance){
    if(tipTitle == null){
        jQuery("#tipTitle").text(notices);
    }else{
        jQuery("#tipTitle").text(tipTitle);
    }
    if(tipInfo == null){
        jQuery("#tipInfo").text("")
    }else{
        jQuery("#tipInfo").text(tipInfo);
    }
    if(sure == null){
        jQuery("#sure").html(shequ_confirm);
    }else{
        jQuery("#sure").html(sure);
    }
    if(cance == null){
        jQuery("#cancel").html(shequ_cancel);
    }else{
        jQuery("#cancel").html(cance);
    }
}
function showTips(tip) {
    if(tip == null){
        tip = {};
    }
    if(!!tip.sure){
        jQuery("#sure")[0].onclick = function () {tip.sure();};
    }else{
        jQuery("#sure")[0].onclick = function () {jQuery("#shequErrorPopTips").hide();}
    }
    if(!!tip.canc){
        jQuery("#cancel")[0].onclick = function () {tip.canc();};
    }else{
        jQuery("#cancel")[0].onclick = function () {jQuery("#shequErrorPopTips").hide();}
    }
    jQuery("#shequErrorPopTips").show();
}
function removeTheme(tid, fid1, fid2) {
    jQuery.post("/shequ/new/bbsThemes/del.do", {tid: tid, fid1: fid1, fid2: fid2}, function (data, status) {
        if (status == "success") {
            if (data == "success") {
                window.location.reload();
            } else if (data == "noPower") {
                addTip("你没有权限，你删个毛线！");
                showTips();
            } else if (data == "error") {
                addTip(shequ_deleteError);
                showTips();
            } else if (data == "hadDeleted") {
                addTip("都删了你还删！你是猪吗！");
                showTips();
            } else if (data == "notLogin") {
                addTip("滚去登录！");
                showTips();
            } else if (data == "notExit") {
                addTip("没有的东西你删毛线啊！");
                showTips();
            }
        } else {
            addTip("请求失败！稍后再试！");
            showTips();
        }
    },'html');
}
document.getElementsByClassName = function(eleClassName)
{
    var getEleClass = [],
		myclass = new RegExp("\\b" + eleClassName + "\\b"),
		elem = this.getElementsByTagName("*");
    for (var h = 0; h < elem.length; h++)
    {
        var classes = elem[h].className;
        if (myclass.test(classes)) getEleClass.push(elem[h]);
    }
    return getEleClass;
};
function hasClass(ele, cls) {
    return ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}

function addClass(ele, cls) {
    if (!this.hasClass(ele, cls)) ele.className += " " + cls;
}

function removeClass(ele, cls) {
    if (hasClass(ele, cls)) {
        var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
        ele.className = ele.className.replace(reg, ' ');
    }
}
function openSide(obj, sbj, elem) {
    var d = document,
		o = d.getElementById(obj),
		s = d.getElementById(sbj),
		w = d.getElementById(elem);
    if (!o) return false;
    if (!s) return false;
    if (!w) return false;
	o.onselectstart = function(){ return false; };
    o.onmousedown = function() {
        if (hasClass(s, "side-open") || hasClass(w, "main-open")) {
            removeClass(s, "side-open");
            removeClass(w, "main-open");
			w.parentNode.className="bbs-wapper";
            this.childNodes[0].nodeValue = "\u5C55\u5F00\u5E16\u5B50\u5217\u8868";
            this.className = "main-skills";
            writeSideCookie("close");
        } else {
            addClass(s, "side-open");
            addClass(w, "main-open");
			w.parentNode.className="bbs-wapper bbs-wapper-tips";
            this.childNodes[0].nodeValue = "\u5173\u95ED\u5E16\u5B50\u5217\u8868";
            this.className = "main-skills-tips";
            writeSideCookie("open");
        }
    };
}
function showTagList(obj, tag) {
    var d = document,
		o = d.getElementsByClassName(obj);
    if (!o) return false;
    for (var i = 0; i < o.length; i++) {
        o[i].onmousedown = function(e) {
            var tags = this.parentNode.getElementsByTagName(tag)[0];
            if (tags.style.display == "none") {
                tags.style.display = "";
                removeClass(this, "col-btn-open");

            } else {
                tags.style.display = "none";
                addClass(this, "col-btn-open");

            }
        };
    }
}

function readSideCookie()
{
    var cookies = document.cookie.split(';'),
		cookie = '';
    for (var i = 0; i < cookies.length; i++) {
        cookie = cookies[i].split('=');
        if (cookie[0].replace(/^\s+|\s+$/g, '') == "sidestatus") {
            return (cookie.length <= 1) ? "" : unescape(cookie[1].replace(/^\s+|\s+$/g, ''));
        }
    }
    return null;
}
function writeSideCookie(status)
{
    document.cookie = "sidestatus=" + status + "; path=/";
}

openSide("main-skills", "side-tips", "main-tips");
showTagList("col-btn", "table");


/************select \u6A21\u62DF*************/


function boxSelect(obj, elem) {
    var nmove,d = document,
		o = d.getElementById(obj),
		s = d.getElementById(elem);
    if (!o) {
        return false;
    }
    ;
    if (!s) {
        return false;
    }
    ;
    o.onmousedown = function() {
        clearTimeout(nmove);
        if (s.className == "cur") {
            s.className = "";
        } else {
            s.className = "cur";
        }
    };
    s.onmouseover = function() {
        clearTimeout(nmove);
    };
	o.onmouseover = function() {
        clearTimeout(nmove);
    };
    o.onmouseout = function() {
        nmove = setTimeout(function() {
            s.className = "";
        }, 100);
    };
    for (var i = 0; i < s.getElementsByTagName("li").length; i++) {
        s.getElementsByTagName("li")[i].onmouseover = function() {
            this.className = "ahover";
        };
        s.getElementsByTagName("li")[i].onmouseout = function() {
            this.className = "";
        };
        s.getElementsByTagName("li")[i].onmousedown = function() {
            s.className = "cur";
            o.childNodes[0].childNodes[0].nodeValue = this.childNodes[0].nodeValue;
        };
    }

}
boxSelect("datatable-btn","datatable-tags");
boxSelect("datatable-btn0","datatable-tags0");
boxSelect("datatable-btn1","datatable-tags1");
boxSelect("sear-btn", "sear-tags");
boxSelect("sear-btn0", "sear-tags0");


/************select \u56FE\u7247 \u6A21\u62DF*************/


function imgSelect(obj, elem) {
    var nmove,d = document,
		o = d.getElementById(obj),
		s = d.getElementById(elem);
    if (!o) {
        return false;
    }
    ;
    if (!s) {
        return false;
    }
    ;
    o.onmousedown = function() {
        clearTimeout(nmove);
        if (s.className == "cur") {
            s.className = "";
        } else {
            s.className = "cur";
        }
    };
    s.onmouseover = function() {
        clearTimeout(nmove);
    };
	o.onmouseover = function() {
        clearTimeout(nmove);
    };
    o.onmouseout = function() {
        nmove = setTimeout(function() {
            s.className = "";
        }, 100);
    };
    for (var i = 0; i < s.getElementsByTagName("li").length; i++) {
        s.getElementsByTagName("li")[i].onmouseover = function() {
            this.className = "ahover";
        };
        s.getElementsByTagName("li")[i].onmouseout = function() {
            this.className = "";
        };
        s.getElementsByTagName("li")[i].onmousedown = function() {
            s.className = "cur";
            o.getElementsByTagName("img")[0].src = this.getElementsByTagName("img")[0].src;
            o.getElementsByTagName("img")[0].alt = this.getElementsByTagName("img")[0].alt;
        };
    }

}
imgSelect("img-btn", "img-tags");


/************select \u56FE\u7247 \u6A21\u62DF*************/


function imgSelect(obj, elem) {
    var nmove,d = document,
		o = d.getElementById(obj),
		s = d.getElementById(elem);
    if (!o) {
        return false;
    }
    ;
    if (!s) {
        return false;
    }
    ;
    o.onmousedown = function() {
        clearTimeout(nmove);
        if (s.className == "cur") {
            s.className = "";
        } else {
            s.className = "cur";
        }
    };
    s.onmouseover = function() {
        clearTimeout(nmove);
    };
	o.onmouseover = function() {
        clearTimeout(nmove);
    };
    o.onmouseout = function() {
        nmove = setTimeout(function() {
            s.className = "";
        }, 100);
    };
    for (var i = 0; i < s.getElementsByTagName("li").length; i++) {
        s.getElementsByTagName("li")[i].onmouseover = function() {
            this.className = "ahover";
        };
        s.getElementsByTagName("li")[i].onmouseout = function() {
            this.className = "";
        };
        s.getElementsByTagName("li")[i].onmousedown = function() {
            s.className = "cur";
            o.getElementsByTagName("img")[0].src = this.getElementsByTagName("img")[0].src;
            o.getElementsByTagName("img")[0].alt = this.getElementsByTagName("img")[0].alt;
            var iconid = this.getElementsByTagName("img")[0].id;
            document.getElementById("themeiconid").value = iconid.substring(5, iconid.length);
        };
    }

}
imgSelect("img-btn", "img-tags");

/************select skills \u6A21\u62DF*************/


function skillsSelect(obj, elem, val) {
    var nmove,d = document,
		o = d.getElementById(obj),
		s = d.getElementById(elem),
    	v = d.getElementById(val);
    if (!o) {
        return false;
    }
    ;
    if (!s) {
        return false;
    }
    ;
    if (!v) {
        return false;
    }
    ;
    o.onmousedown = function() {
        clearTimeout(nmove);
        if (s.className == "cur") {
            s.className = "";
        } else {
            s.className = "cur";
        }
    };
    s.onmouseover = function() {
        clearTimeout(nmove);
    };
	o.onmouseover = function() {
        clearTimeout(nmove);
    };
    o.onmouseout = function() {
        nmove = setTimeout(function() {
            s.className = "";
        }, 100);
    };
    for (var i = 0; i < s.getElementsByTagName("li").length; i++) {
        s.getElementsByTagName("li")[i].onmouseover = function() {
            this.className = "ahover";
        };
        s.getElementsByTagName("li")[i].onmouseout = function() {
            this.className = "";
        };
        s.getElementsByTagName("li")[i].onmousedown = function() {
            s.className = "cur";
            v.value = this.childNodes[0].nodeValue;
        };
    }

}
skillsSelect("skills-box1", "skills-tags1", "text1");
skillsSelect("skills-box2", "skills-tags2", "text2");
skillsSelect("skills-box3", "skills-tags3", "text3");
skillsSelect("skills-box4", "skills-tags4", "text4");
skillsSelect("skills-box5", "skills-tags5", "text5");
skillsSelect("skills-box6", "skills-tags6", "text6");
/*high-search*/
function changeClass(obj, elem) {
    var d = document,
		o = d.getElementById(obj),
		s = d.getElementById(elem);
    if (!o) {
        return false;
    }
    ;
    if (!s) {
        return false;
    }
    ;
    s.onmousedown = function() {
        if (hasClass(s, "cur")) {
            removeClass(o, "display-n");
            removeClass(s, "cur");
        } else {
            addClass(o, "display-n");
            addClass(s, "cur");
        }
    };
}
changeClass("article-search", "high-search");


/*bbskills checkbox*/
function bbsChenckbox(obj,elem,tags){
	var o=document.getElementById(obj);
	if(!o){ return false;}
	var lis=o.getElementsByTagName(tags);
	for(var i=0;i<lis.length;i++){
		var chks=lis[i].getElementsByTagName(elem)[0];
		//if(chks.checked==true){chks.checked=false};
		chks.onclick=function(){
			if(this.checked==true){
					this.parentNode.className="cur";
				}else{
					this.parentNode.className="";
					}
			};
		}
}
bbsChenckbox("sel-state1", "input", "li");
bbsChenckbox("sel-state2", "input", "li");

/*----------tagSwitch--------*/
function tagSwitch(selfObj, boxObj) {
    var s = document.getElementById(selfObj);
    if (!s) {
        return false;
    }
    ;
    var lis = s.getElementsByTagName("li");
    for (var i = 0; i < lis.length; i++) {
        var tags = document.getElementById(boxObj + i);
        if (!tags) {
            return false;
        }
        ;
        tags.style.display = "none";
        if (lis[i].className == "cur") {
            tags.style.display = "block";
        }
        lis[i].onmousedown = function() {
            if (this.className == "cur") {
                return false;
            }
            else {
                thiSwitch(this);
            }
        };
    }
    function thiSwitch(obj) {         //thiSwitch
        for (var j = 0; j < lis.length; j++) {
            var tags = document.getElementById(boxObj + j);
            if (!tags) {
                return false;
            }
            ;
            if (lis[j] == obj) {
                lis[j].className = "cur";
                tags.style.display = "block";
            }
            else {
                lis[j].className = "";
                tags.style.display = "none";
            }
        }
    }
}
//在mypost.jsp引用，区分分页
function boxShow(t){
	if(t == 2){
		document.getElementById("box1").style.display = "block";
		document.getElementById("my-side").getElementsByTagName("li")[1].className = "cur";
		document.getElementById("my-side").getElementsByTagName("li")[0].className = "";
		document.getElementById("box0").style.display = "none";
	}
}
tagSwitch("my-side", "box");

/*\u9694\u884C\u53D8\u8272*/
function rowCycle(boxObj, rowTag, newClass, oldClass) {
    var obj = document.getElementById(boxObj);
    if (!obj) {
        return false;
    }
    ;
    var tags = obj.getElementsByTagName(rowTag);
    for (var i = 0; i < tags.length; i++) {
        if (i % 2 == 0) {
            tags[i].className = oldClass;
        } else {
            tags[i].className = newClass;
        }
    }
}
rowCycle("box7", "tbody", "actived", "");

//从DOM获取上一个兄弟对象节点
function prev(elem){
	do{
		elem = elem.previousSibling;
	}while(elem && elem.nodeType != 1);
	return elem;
}

//从DOM获取下一个兄弟对象节点
function next(elem){
	do{
		elem = elem.nextSibling;
	}while(elem && elem.nodeType != 1);
	return elem;
}

function operFirstTree(obj,url){
	var subDiv = next(obj.parentNode);
	var imgs = obj.parentNode.getElementsByTagName("img");
	if(imgs == null || imgs.length<=0){
		return;
	}
	if(subDiv.style.display == "none"){
		subDiv.style.display = "";
		imgs[0].src = url+"/image/shequ/icon/tree-min.gif";
		imgs[1].src = url+"/image/shequ/icon/tree-files-open.gif";
	}else{
		subDiv.style.display = "none";
		imgs[0].src = url+"/image/shequ/icon/tree-max.gif";
		imgs[1].src = url+"/image/shequ/icon/tree-files.gif";
	}
}

function operTree(obj,url){
	var subDiv = next(obj.parentNode);
	var imgs = obj.parentNode.getElementsByTagName("img");
	if(imgs == null || imgs.length<=0){
		return;
	}
	if(subDiv.style.display == "none"){
		subDiv.style.display = "";
		imgs[0].src = url+"/image/shequ/icon/tree-min-sel.gif";
		imgs[1].src = url+"/image/shequ/icon/tree-files-open.gif";
	}else{
		subDiv.style.display = "none";
		imgs[0].src = url+"/image/shequ/icon/tree-max-sel.gif";
		imgs[1].src = url+"/image/shequ/icon/tree-files.gif";
	}
}

function operLastTree(obj,url){
	var subDiv = next(obj.parentNode);
	var imgs = obj.parentNode.getElementsByTagName("img");
	if(imgs == null || imgs.length<=0){
		return;
	}
	if(subDiv.style.display == "none"){
		subDiv.style.display = "";
		imgs[0].src = url+"/image/shequ/icon/tree-min-end.gif";
		imgs[1].src = url+"/image/shequ/icon/tree-files-open.gif";
	}else{
		subDiv.style.display = "none";
		imgs[0].src = url+"/image/shequ/icon/tree-max-end.gif";
		imgs[1].src = url+"/image/shequ/icon/tree-files.gif";
	}
}

/**
 * 切换语言
 */
function switchLanguage(tId,languageType){
	var callback={
					okBack:function(){
						var url = "/shequ/bbsModeratorManager/themeSwitchLanguage.do?random="+Math.round(Math.random()*100);
						var param={tId:tId,languageType:languageType};
						jQuery.post(url,param,function(data){
							if(data == 1){
								okcoinAlert("切换成功!","",null);
								window.location.href= document.getElementById("coinMainUrl").value+"/shequ/bbsModeratorManager/themeManager.do";
							}else{
								okcoinAlert("切换失败!",null,null);
							}
						});
					},
				 	noBack:function(){

					}
				 };
	okcoinAlert("确定要切换吗?",null,callback);
}
/**
* 公用下拉选择框－－显示出选择的内容层
*/
jQuery(".userAdmin").live("click",function(){
	var $selSpan = jQuery(this);
	var $selContent = $selSpan.parent().find(".userAdminContent");
	//当下拉框就一个值时不显示
	var showFlag = true;
	if($selContent.find("li").length < 2){
		showFlag = false;
	}
	if($selContent.is(":hidden") && showFlag){
		$selContent.show();
	}else{
		$selContent.hide();
	}
});
